/*
 * Copyright 2013 Walter Lütgenau.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package offset.nodes.client.dialog.navigation.model;

import java.util.Arrays;
import java.util.HashSet;
import netscape.javascript.JSObject;

/**
 *
 * @author
 * Walter
 * Lütgenau
 */
public class JSElement extends JSNode {
    private static final String F_SCROLL_INTO_VIEW = "scrollIntoView";
    public static final String E_DIV = "div";
    private static HashSet<String> blockElements = new HashSet<String>(Arrays.asList(new String[] {
        "address", "blockquote", "center", "del", "dir", 
        "div", "dl", "fieldset", "form", "h1", "h2", "h3", 
        "h4", "h5", "h6", "hr", "ins", "isindex", "menu", 
        "noframes", "noscript", "ol", "p", "pre", "table", "tbody", "tr", "ul", "td"
    }));

    public JSElement(JSObject object) {
        super(object);
    }
    
    public JSElement(JSNode node) {
        this(node.getObject());
    }
    
    /**
     * Scroll the element into the view of the containing window
     */
    public void scrollIntoView() {
        Object result = getObject().call(F_SCROLL_INTO_VIEW, null);     
    }
    
    /**
     * Is the element name the name of a block element?
     * 
     * @param elementName the element name
     * @return the answer
     */
    public static boolean isBlock(String elementName) {
        return blockElements.contains(elementName);
    }
    
}
